<?php include('../../variables/variables.php'); ?>

<?php

if(!session_id()) session_start(); 
$con = mysql_connect($dbserver, $dbuser, $dbpass);
if ($con)
{
	mysql_select_db($db, $con);
	
if(!isset($_POST['prev_media_id']))
$_POST['prev_media_id'] = $_POST['media_id'];

	if ($_POST['inventory_id'] && $_POST['media_id'] && isset($_POST['cost']) && $_POST['media_type_id'])
	{	
		$q = fquery($update_inventory, array( $_POST['cost']*100, $_POST['media_id'], $_POST['media_type_id'], $_POST['inventory_id']));

		$result = mysql_query($q);
		mysql_close($con);
		if ($result)
		{
			header("location: /manage_inventory.php?action=display&id=". $_POST['prev_media_id']. "&msg=Inventory Updated successfully!");
		}
		else
		{
			header("location: /manage_inventory.php?action=display&id=". $_POST['prev_media_id']. "&err=Failed to update the inventory!");// <br> ". $q);
		}
	}
	else
	{
		mysql_close($con);
		header("location: /manage_inventory.php?action=display&id=". $_POST['prev_media_id']. "&err=Please fill in all fields.");
	}
}

?>
